323A - Black-and-White Cube - CodeForces Solution


combinatorics constructive algorithms *1600

Please click on ads to support us..

C++ Code:

#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <map>
#include <cstring>
#include <set>
#include <numeric>
#include <array>
#include <algorithm>
#define endl '\n'
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb push_back
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pii>
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define rep(i,a,b) for(int i=a;i<b;i++)
#define sz(x) (int)x.size()
#define debug(x) cout<<#x<<" = "<<x<<endl;
#define lb lower_bound
#define ub upper_bound
#define setbits(x) __builtin_popcountll(x)
#include <stack>
#define unsigned int 
using namespace std;
#include <iostream>
#include <queue>
#include <deque>
#include <vector>
#include <functional>
using namespace std;

#define PI 3.14159265358979323846264
#define ii pair<int,int>
#define iii pair<int, pair<int, int>>





using namespace std;
#define int long long
int gcd(int a, int b)
{
    if(b==0)
        return a;
    return gcd(b, a%b);
}

void normalize(vector<int> &v)
{
    set<int> s;
    for(auto i : v)
        s.insert(i);
    map<int, int> m;
    int cnt = 1;
    for(auto i : s)
        m[i] = cnt++;
    for(auto &i : v)
        i = m[i];
    
}


int get(int n)
{
    if(n == 1)
        return 1;
    return n + get(n/2);
}
const int n = 2e5 + 1;
int MOD = 1e9 + 7;
//  int MOD =  998244353;
int fact[1000000];
map<string, int> mp;

/// @brief 
/// @param n 
/// @return 
int sum(int n)
{
    return n * (n+1 ) /2 ;
}
long long modular_inverse(long long a, long long m) {
    // Extended Euclidean Algorithm
    long long m0 = m;
    long long x0 = 0, x1 = 1;

    while (a > 1) {
        long long q = a / m;
        long long t = m;

        m = a % m, a = t;
        t = x0;

        x0 = x1 - q * x0;
        x1 = t;
    }

    if (x1 < 0) {
        x1 += m0;
    }

    return x1;
}
long long modInverse(long long a) {
    long long p = MOD;
    long long result = 1;
    long long exponent = p - 2;

    while (exponent > 0) {
        if (exponent % 2 == 1) {
            result = (result * a) % p;
        }
        a = (a * a) % p;
        exponent /= 2;
    }

    return result;
}

int comb(int n, int k) {
    if(k > n)
        return 0;
    if(k < 0)
        return 0;
    if(k>n-k)
        k = n-k;
    int ret = 1;
    for(int i = 0;i<k;i++)
    {
        ret *= n-i;
        ret /= i+1;
    }

    return ret;

}



int combMod(int n, int k) {
    if(n < k) return 0;
    return fact[n] * modInverse(fact[k]) %MOD * modInverse(fact[n-k]) % MOD;
}

int permute(int n, int k) {
    if(k > n)
        return 0;
    int ret = 1;
    ret = fact[n] * modInverse(fact[n - k]) % MOD;
    return ret;
}
int power(int a, int b)
{
    if(b == 0)
        return 1;
    int ret = power(a, b/2);
    ret *= ret;
    ret %= MOD;
    if(b&1)
        ret *= a;
    ret %= MOD;
    return ret;
}
bool check(vector<int> &v, int k)
{
    int n = v.size();
    int cnt = 0;
    vector<int> b;
    for(int i = n-k;i<n;i++)
        b.push_back(v[i]);
    for(int i = 0;i<n-k;i++)
        b.push_back(v[i]);
    for(int i = 0;i<n;i++)
        cnt += b[i] > v[i];
    return cnt >= k;

}


int sum1toN(int n)
{
    return n * (n+1) / 2;
}

int sum1toN(int l, int r)
{
    return sum1toN(r) - sum1toN(l-1);
}

int sumDigits(int n)
{
    int ret = 0;
    while(n)
    {
        ret += n % 10;
        n /= 10;
    }
    return ret;
}

int get(char c) {
    if('0' <= c && c <= '9')
        return c - '0';
    if('A' <= c && c <= 'Z')
        return c - 'A' + 10;
    if('a' <= c && c <= 'z')
        return c - 'a' + 36;
    if(c == '-')
        return 62;
    return 63;
}
vector<vector<int>> result;
vector<int> currentSet;
vector<int> currentPut;


void powerSet(int i = 0) {
    if(i == currentSet.size()) {

        result.push_back(currentPut);
        return;
    }

    currentPut.push_back(currentSet[i]);
    powerSet(i+1);

    currentPut.pop_back();
    powerSet(i+1);
    


}
void solve() {
   
    int n;
    cin>>n;
    if(n % 2 == 1) {
        cout<<-1<<endl;
        return;
    }
    map<int, char>eval;
    eval[0] = 'w';
    eval[1] = 'b';

    for(int layer = 0; layer < n; layer++) {
        int c = layer % 2;

        for(int i = 0; i < n; i++) {
            for(int j = 0; j < n; j++) {
                int level = min({i, j, n - i - 1, n - j - 1});
                int cur = level %2;
                if(c) cur = !cur;
                cout<<eval[cur];
            }
            cout << endl;
        }
        cout << endl;



    }

    
                

}
            



main() {
    IOS;
    fact[0] = 1;
    
    for(int i=1;i<=n;i++)
        fact[i] = i*fact[i-1]%MOD;
    int t = 1;
    //cin >> t;
    //while(t--)
        solve();
    

    return 0;
    
}

// Path: eatingCandies.cpp


Comments

Submit
0 Comments
More Questions

1602B - Divine Array
1594B - Special Numbers
1614A - Divan and a Store
2085. Count Common Words With One Occurrence
2089. Find Target Indices After Sorting Array
2090. K Radius Subarray Averages
2091. Removing Minimum and Maximum From Array
6. Zigzag Conversion
1612B - Special Permutation
1481. Least Number of Unique Integers after K Removals
1035. Uncrossed Lines
328. Odd Even Linked List
1219. Path with Maximum Gold
1268. Search Suggestions System
841. Keys and Rooms
152. Maximum Product Subarray
337. House Robber III
869. Reordered Power of 2
1593C - Save More Mice
1217. Minimum Cost to Move Chips to The Same Position
347. Top K Frequent Elements
1503. Last Moment Before All Ants Fall Out of a Plank
430. Flatten a Multilevel Doubly Linked List
1290. Convert Binary Number in a Linked List to Integer
1525. Number of Good Ways to Split a String
72. Edit Distance
563. Binary Tree Tilt
1306. Jump Game III
236. Lowest Common Ancestor of a Binary Tree
790. Domino and Tromino Tiling